﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class ListSP_Xuat
{
    public List<SanPham_Xuat> sp { get; set; }
    public ListSP_Xuat()
    {
        sp = new List<SanPham_Xuat>();
    }
    public void XoaSP(String masp)
    {
        foreach (SanPham_Xuat a in sp)
        {
            if (a.masp == masp)
            {
                sp.Remove(a);
                break;
            }
        }
        
    }
    public void CapNhatSP(String masp, float soluong, float dongia)
    {
        int idx = -1;
        foreach (SanPham_Xuat a in sp)
        {
            if (a.masp == masp)
            {
                idx = sp.IndexOf(a);
                break;
            }
        }
        sp[idx].soluong = soluong;
        sp[idx].dongia = dongia;
        sp[idx].thanhtien = soluong * dongia;
    }
    public void ThemSP(SanPham_Xuat sp_xuat)
    {
        bool flag = false;
        int idx = -1;
        foreach (SanPham_Xuat a in sp)
        {
            if (a.tensp == sp_xuat.tensp)
            {
                flag = true;
                idx = sp.IndexOf(a);
                break;
            }
        }
        if (flag)
        {
            sp[idx].soluong = sp_xuat.soluong ;
            sp[idx].dongia = sp_xuat.dongia;
            sp[idx].thanhtien = sp_xuat.soluong*sp_xuat.dongia;
        }
        else
        {
            sp.Add(sp_xuat);
        }
    }
}

